package com.jy.adscm.operation.aftersales.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.aftersales.bean.ShRepairUpkeepRepairPartsMaterialList;
import com.jy.adscm.operation.aftersales.service.ShRepairUpkeepRepairPartsMaterialListService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
   维修领用备件
 * @author zyl
 * @since 2019-08-29
 */
@RestController
@RequestMapping("/adscm/operation/aftersales/shRepairUpkeepRepairPartsMaterialList")
public class ShRepairUpkeepRepairPartsMaterialListController {
    @Autowired
    ShRepairUpkeepRepairPartsMaterialListService shRepairUpkeepRepairPartsMaterialListService;
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;


    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody ShRepairUpkeepRepairPartsMaterialList shRepairUpkeepRepairPartsMaterialList, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        shRepairUpkeepRepairPartsMaterialList.setCreator(token.getUser().getId().toString());
        shRepairUpkeepRepairPartsMaterialList.setCreateTime(new Date());
        boolean insert = shRepairUpkeepRepairPartsMaterialListService.insertShRepairUpkeepRepairPartsMaterialList(shRepairUpkeepRepairPartsMaterialList);
        return  new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("selectByPid/{pid}")
    public SimpleCoreResponse insert(@PathVariable Integer pid, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<ShRepairUpkeepRepairPartsMaterialList> shRepairUpkeepRepairPartsMaterialLists= shRepairUpkeepRepairPartsMaterialListService.selectByPid(pid);
        return  new SimpleCoreResponse("200","新增成功",shRepairUpkeepRepairPartsMaterialLists);
    }
    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
         Boolean  result=    shRepairUpkeepRepairPartsMaterialListService.deleteShRepairUpkeepRepairPartsMaterialList(id);
        return  new SimpleCoreResponse("200","新增成功",result);
    }


}

